package com.sanuo.pico.act.work;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;

import com.menu.app.it.NumUI;
import com.menu.app.ui.SwitchButton;
import com.menu.app.util.Constant;
import com.sanuo.pico.App;
import com.sanuo.pico.adapter.SettingsAdapter;
import com.sanuo.pico.databinding.ActivitySettingsBinding;
import com.sanuo.pico.utils.Command;
import com.sanuo.pico.utils.Const;

public class SettingsActivity extends BaseWorkActivity implements NumUI {

    ActivitySettingsBinding binding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivitySettingsBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.back.setOnClickListener(v -> {
            finish();
        });
        SettingsAdapter adapter = new SettingsAdapter(this, this);
        binding.list.setLayoutManager(new GridLayoutManager(this, 2));
        binding.list.setAdapter(adapter);

        if (Const.pwd != null && Const.pwd.startsWith("158")) {
            boolean bo = Constant.hasLightCtrl();
            if (bo) {
                binding.lightSwitch.openButton();
            } else {
                binding.lightSwitch.closeButton();
            }
            binding.lightSwitch.setOnSwitchListener(new SwitchButton.OnSwitchListener() {
                @Override
                public void onSwitchChange(View view, boolean z2) {
                    Constant.setLightCtrl(z2);
                }
            });
        } else {
            binding.light.setVisibility(View.GONE);
        }
        Activity ac = App.getApp().findActivity(PassActivity.class);
        if (ac != null) {
            ac.finish();
        }
    }

    @Override
    public void onClickNum(int position) {
        if (position < 8) {
            Command.sendTouchEvent(0, 0x60 + position);
        } else if (position == 8) {
            Command.sendTouchEvent(0, 0x6a);
        } else if (position == 9) {
            //msn
        }
    }
}
